<style lang="scss" scoped>
</style>

<template>
    <div class="infobody">
        <top-bar @partToggle="partToggle" @toggleEditStatus="toggleEditStatus" @saveItem="saveItem" @saveTemp="saveTemp" @clickNextStep="clickNextStep" ref="topbar"></top-bar>
        <div class="content">
          <loading v-model="spinShow"></loading>
          <p class="form-title">{{formTitle}}</p>
          <div id="part1" v-show="partShow"> 
              <Form :model="sampleComplete" ref="sampleCompleteOne" :rules="ruleFormOne">
                <div class="title">
                    个人信息
                    <span class="title-right" @click="personToggle=!personToggle" v-show="personToggle"><Icon type="minus-round"></Icon></span>
                    <span class="title-right" @click="personToggle=!personToggle" v-show="!personToggle"><Icon type="plus-round"></Icon></span>  
                </div>
                <div class="info" v-show="personToggle">         
                    <FormItem label="userId" hidden>
                        <Input v-model="sampleComplete.sampleInfoEntity.userId" />
                    </FormItem>        
                    <FormItem  label="姓名" prop="sampleInfoEntity.name">
                        <Input :disabled="status"  v-model="sampleComplete.sampleInfoEntity.name" placeholder="请输入姓名" />
                    </FormItem>
                    <FormItem label="性别" prop="sampleInfoEntity.sex">
                        <Select :disabled="status" v-model="sampleComplete.sampleInfoEntity.sex" placeholder="请选择性别" >
                            <Option value="男">男</Option>
                            <Option value="女">女</Option>
                        </Select>
                    </FormItem>
                    <FormItem label="出生日期" prop="sampleInfoEntity.birthday">
                      <!-- MUI方式 -->      
                      <div class="ivu-input-wrapper ivu-input-type">
                          <div v-bind:class="{'div-disabled':status,'ivu-input':true}" @click="confirmDate('birthday')">
                            <span v-if="sampleComplete.sampleInfoEntity.birthday">{{sampleComplete.sampleInfoEntity.birthday}}</span>
                              <span v-else   style="color:#bbbec4;">请选择出生日期</span>
                            </div>
                        </div>    
                    </FormItem>
                    <FormItem label="样本编号" prop="sampleInfoEntity.sampleNum">
                        <Input :disabled="status" v-model="sampleComplete.sampleInfoEntity.sampleNum" placeholder="请输入样本编号" />
                    </FormItem>
                    <FormItem label="申请医院">
                        <Input :disabled="status" v-model="sampleComplete.sampleInfoEntity.hospital" placeholder="请输入医院名称" />
                    </FormItem>
                    <FormItem label="申请科室">
                        <Input :disabled="status" v-model="sampleComplete.sampleInfoEntity.section" placeholder="请输入科室名称" />
                    </FormItem>
                    <FormItem label="申请医生">
                        <Input :disabled="status" v-model="sampleComplete.sampleInfoEntity.doctor" placeholder="请输入医生姓名" />  
                    </FormItem>     
                    <FormItem label="报告邮寄信息" prop="sampleInfoEntity.addressMessage">
                        <AutoComplete :disabled="status" v-model="sampleComplete.sampleInfoEntity.addressMessage" :data="addressList" :filter-method="filterAddress"   placeholder="请输入报告邮寄信息" ></AutoComplete>
                    </FormItem> 
                    <FormItem label="癌症类型" prop="sampleInfoEntity.cancerType">
                        <Input :disabled="status" v-model="sampleComplete.sampleInfoEntity.cancerType" type="textarea"  placeholder="请输入癌症类型" />
                    </FormItem>
                    <FormItem label="诊断年龄" prop="sampleInfoEntity.age">
                        <Input :disabled="status" v-model="sampleComplete.sampleInfoEntity.age" placeholder="请输入年龄" number />
                    </FormItem>      
                    <FormItem label="癌症类型2" >
                        <Input :disabled="status" v-model="sampleComplete.sampleInfoEntity.cancerTypeTwo" type="textarea"  placeholder="请输入癌症类型" />
                    </FormItem>
                    <FormItem label="诊断年龄2" >
                        <Input :disabled="status" v-model="sampleComplete.sampleInfoEntity.ageTwo" placeholder="请输入年龄" number />
                    </FormItem>     
                    <FormItem label="癌症类型3" >
                        <Input :disabled="status" v-model="sampleComplete.sampleInfoEntity.cancerTypeThree" type="textarea"  placeholder="请输入癌症类型" />
                    </FormItem>
                    <FormItem label="诊断年龄3">
                        <Input :disabled="status" v-model="sampleComplete.sampleInfoEntity.ageThree" placeholder="请输入年龄" number />
                    </FormItem>     

                    <FormItem label="肿瘤史描述">
                        <Input :disabled="status" v-model="sampleComplete.sampleInfoEntity.describe" type="textarea"  placeholder="请输入肿瘤史描述" />
                    </FormItem>  
                    <FormItem label="检测类型" prop="sampleInfoEntity.testType">
                        <Select :disabled="status" v-model="sampleComplete.sampleInfoEntity.testType" placeholder="请选择检测类型">
                            <Option value="全外显子检测安捷伦V6">全外显子检测安捷伦V6 </Option>
                            <Option value="全外显子检测IDT">全外显子检测IDT</Option>
                            <Option value="BRCA1,2">BRCA1,2</Option>
                        </Select>
                    </FormItem>
                    <FormItem label="采样日期" prop="sampleInfoEntity.sampleDate">
                        <!-- MUI方式 -->
                        <div class="ivu-input-wrapper ivu-input-type">
                            <!-- <div v-bind:class="{'div-disabled':status,'ivu-input':true}" @click="confirmSampleDate"> -->
                            <div v-bind:class="{'div-disabled':status,'ivu-input':true}" @click="confirmDate('sampleDate')">
                              <span v-if="sampleComplete.sampleInfoEntity.sampleDate">{{sampleComplete.sampleInfoEntity.sampleDate}}</span>
                              <span v-else   style="color:#bbbec4;">请选择采样日期</span>
                            </div>
                        </div>   
                    </FormItem>
                    <FormItem label="样本类型" prop="sampleInfoEntity.sampleModeArray" >            
                        <CheckboxGroup v-model="sampleComplete.sampleInfoEntity.sampleModeArray">
                          <Checkbox label="石蜡包埋组织/切片" :disabled="status"></Checkbox>
                          <Checkbox label="手术/穿刺组织" :disabled="status"></Checkbox>
                          <Checkbox label="胸/腹水" :disabled="status"></Checkbox>
                          <Checkbox label="EDTA抗凝" :disabled="status"></Checkbox>
                          <Checkbox label="Streck管" :disabled="status"></Checkbox>
                          <Checkbox label="其他" :disabled="status"></Checkbox>
                        </CheckboxGroup>
                    </FormItem>
                    <FormItem  v-show="sampleComplete.sampleInfoEntity.sampleModeArray?sampleComplete.sampleInfoEntity.sampleModeArray.indexOf('其他')!=-1:false">   
                        <Input :disabled="status" v-model="sampleComplete.sampleInfoEntity.itsSampleModeArray"  placeholder="请输入样本类型" />
                    </FormItem>                            
                    <!-- <FormItem label="样本类型" prop="sampleInfoEntity.sampleMode">
                        <Select :disabled="status" v-model="sampleComplete.sampleInfoEntity.sampleMode" placeholder="请选择样本类型">
                            <Option value="石蜡包埋组织/切片">石蜡包埋组织/切片</Option>
                            <Option value="癌组织">癌组织</Option>
                            <Option value="全血">全血</Option>
                            <Option value="其他">其他</Option>
                        </Select>
                    </FormItem>                     -->
                    <FormItem label="补送样本">
                      <Select :disabled="status" v-model="sampleComplete.sampleInfoEntity.replacesample">
                            <Option value="是">是</Option>
                            <Option value="否">否</Option>
                        </Select>
                    </FormItem>
                    <FormItem label="科研样本">
                       <Select :disabled="status" v-model="sampleComplete.sampleInfoEntity.researchsample">
                            <Option value="是">是</Option>
                            <Option value="否">否</Option>
                        </Select>
                    </FormItem>
                </div>
                <div class="title">
                    阳性位点
                    <span class="title-right" @click="familyToggle=!familyToggle" v-show="familyToggle"><Icon type="minus-round"></Icon></span>
                    <span class="title-right" @click="familyToggle=!familyToggle" v-show="!familyToggle"><Icon type="plus-round"></Icon></span>    
                </div>
                <div class="info" v-show="familyToggle">
                    <div class="note">（当患者亲属不做检测，只做验证时填以下内容）</div>
                    <div v-for="(item, index) in sampleComplete.sampleValidateInfoEntityList" :key="index">
                        <FormItem label="姓名" :prop="'sampleValidateInfoEntityList.' + index + '.vname'"  :rules="{required:true,message:'姓名不能为空',trigger:'blur'}">
                            <Input :disabled="status" v-model="item.vname" placeholder="请输入姓名" />
                        </FormItem>
                        <FormItem label="性别" :prop="'sampleValidateInfoEntityList.' + index + '.vSex'"  :rules="{required:true,message:'性别不能为空',trigger:'change'}">
                            <Select v-model="item.vSex" :disabled="status" placeholder="请选择性别">
                                <Option value="男">男</Option>
                                <Option value="女">女</Option>
                            </Select>
                        </FormItem>
                        <FormItem label="出生日期" :prop="'sampleValidateInfoEntityList.' + index + '.vBirthday'"  :rules="{required:true, validator:validatevBirthday,trigger:'change'}">  
                                                          <!-- MUI方式 -->
                            <div class="ivu-input-wrapper ivu-input-type">
                                <!-- <div v-bind:class="{'div-disabled':status,'ivu-input':true}" @click="confirmVBirthday(index)"> -->
                                <div v-bind:class="{'div-disabled':status,'ivu-input':true}" @click="confirmDate('VBirthday',index)">
                                  <span v-if="item.vBirthday">{{item.vBirthday}}</span>
                                  <span v-else   style="color:#bbbec4;">请选择出生日期</span>
                                </div>
                            </div>  
                        </FormItem>
                        <FormItem label="亲属称谓" :prop="'sampleValidateInfoEntityList.' + index + '.kinship'"  :rules="{required:true,message:'亲属称谓不能为空',trigger:'blur'}">
                            <Input :disabled="status" v-model="item.kinship" placeholder="请输入亲属称谓"/>
                        </FormItem>
                        <FormItem label="样本编号" :prop="'sampleValidateInfoEntityList.' + index + '.sampleNum'"  :rules="{required:true,message:'样本编号不能为空',trigger:'blur'}">
                            <Input :disabled="status" v-model="item.sampleNum" placeholder="请输入样本编号" />
                        </FormItem>
                        <FormItem label="是否患病" :prop="'sampleValidateInfoEntityList.' + index + '.isHaveb'"  :rules="{required:true,message:'请选择是否患病',trigger:'change'}"> 
                            <RadioGroup v-model="item.isHaveb" >
                                <Radio :disabled="status" label="否"></Radio>
                                <Radio :disabled="status" label="是"></Radio>
                            </RadioGroup>
                        </FormItem>  
                        <FormItem v-show="item.isHaveb=='是'">
                            <Input :disabled="status" v-model="item.bName" placeholder="请输入患病名称" />
                        </FormItem> 
                        <div class="longbtn">
                         <Button  :disabled="status" type="primary" @click="deletePositive(index)">删除亲属</Button>  
                        </div>              
                        <hr/>
                    </div>
                    <div class="longbtn">
                      <Button :disabled="status" type="primary" @click="addPositive">点击添加亲属</Button>  
                    </div>
                     
                </div>

                <div class="title">
                    家族史采集表
                    <span class="title-right" @click="projectToggle=!projectToggle" v-show="projectToggle"><Icon type="minus-round"></Icon></span>
                    <span class="title-right" @click="projectToggle=!projectToggle" v-show="!projectToggle"><Icon type="plus-round"></Icon></span>   
                </div>
                <div class="info" v-show="projectToggle">
                    <div class="note">（家族史信息可以评估您与家人的遗传风险，请您尽可能全面的填写家族肿瘤病史信息）</div>
                    <div v-for="(item, index) in sampleComplete.familySampleEntityList" :key="index">
                        <FormItem label="姓名" :prop="'familySampleEntityList.' + index + '.fname'"  :rules="{required:true,message:'姓名不能为空',trigger:'blur'}">
                            <Input :disabled="status" v-model="item.fname"  placeholder="请输入姓名" />
                        </FormItem>
                        <FormItem label="亲属称谓" :prop="'familySampleEntityList.' + index + '.fkinship'"  :rules="{required:true,message:'亲属称谓不能为空',trigger:'blur'}">
                            <Input :disabled="status" v-model="item.fkinship"  placeholder="请输入亲属称谓" />
                        </FormItem>
                        <FormItem label="癌症类型" :prop="'familySampleEntityList.' + index + '.fcancerType'"  :rules="{required:true,message:'癌症类型不能为空',trigger:'blur'}">
                            <Input :disabled="status" v-model="item.fcancerType"  type="textarea"  placeholder="请输入癌症类型" />
                        </FormItem>
                        <FormItem label="患癌年龄" :prop="'familySampleEntityList.' + index + '.fage'"   :rules="{required:true,validator:validateAge,trigger:'blur'}">
                            <Input :disabled="status" v-model="item.fage" placeholder="请输入患癌年龄" number />
                        </FormItem>
                        <FormItem label="是否为双侧或一个器官多个病灶" :prop="'familySampleEntityList.' + index + '.isManyLesion'"  :rules="{required:true,message:'是否为双侧或一个器官多个病灶不能为空',trigger:'change'}">
                            <Select :disabled="status" v-model="item.isManyLesion" >
                                <Option value="0">是</Option>
                                <Option value="1">否</Option>
                                <Option value="2">一个器官多个病灶</Option>
                            </Select>
                        </FormItem>
                        <div class="longbtn">
                          <Button  :disabled="status" type="primary" @click="deleteRelativeHistory(index)">删除亲属</Button>
                        </div>
                        <hr/>
                    </div>
                    <div class="longbtn">
                      <Button :disabled="status" type="primary" @click="addRelativeHistory">点击添加亲属</Button>
                    </div>
                </div>
              </Form>
          </div>
          <div id="part2" v-show="!partShow">
              <Form :model="sampleComplete" ref="sampleCompleteTwo" :rules="ruleFormTwo">
                <div class="title">物流信息</div>
                <div class="info">
                    <FormItem label="快递单号" prop="sampleInfoEntity.logOrderNum">
                        <Input :disabled="status" v-model="sampleComplete.sampleInfoEntity.logOrderNum"  placeholder="请输入快递单号"  />
                    </FormItem>
                        <FormItem label="物流公司">
                        <Input :disabled="status" v-model="sampleComplete.sampleInfoEntity.logisticsCompany"  placeholder="请输入物流公司" />
                    </FormItem>
                </div>
                <div class="title">价格</div>
                <div class="info">
                    <FormItem label="促销渠道">
                        <Input :disabled="status" v-model="sampleComplete.sampleInfoEntity.disChannel"  placeholder="请输入促销渠道" />
                    </FormItem>
                    <FormItem  label="经销商" >
                        <Select :disabled="moneyStatus"  v-model="sampleComplete.sampleInfoEntity.agentid" clearable placeholder="请选择经销商" @on-change="agentChange" >
                            <Option v-for="item in agentList" :value="item.id" :key="item.id" :label="item.agentName "></Option>
                        </Select>
                    </FormItem>   
                    <FormItem  label="医院" >
                        <Select :disabled="moneyStatus"  v-model="sampleComplete.sampleInfoEntity.hospitalid" clearable placeholder="请选择医院" >
                            <Option v-for="item in hospitalList" :value="item.hospitalId" :key="item.hospitalId" :label="item.hospitalName "></Option>
                        </Select>
                    </FormItem>  
                     <FormItem label="预付款余额" >
                        <Input :disabled="true" v-model="payment" />
                    </FormItem>                                         
                    <FormItem label="支付方式" prop="sampleInfoEntity.paymentMethod">
                      <RadioGroup v-model="sampleComplete.sampleInfoEntity.paymentMethod">
                        <Radio :disabled="moneyStatus" label="预付">预付</Radio>
                        <Radio :disabled="moneyStatus" label="现付">现付</Radio>                            
                      </RadioGroup>
                    </FormItem>
                    
                    <FormItem label="付款方式" v-show="sampleComplete.sampleInfoEntity.paymentMethod=='现付'">
                        <Select :disabled="moneyStatus" v-model="sampleComplete.sampleInfoEntity.payment" placeholder="请选择付款方式">
                            <Option :value="parseInt(1)">微信</Option>
                            <Option :value="parseInt(2)">支付宝</Option>
                            <Option :value="parseInt(3)">POS机</Option>
                            <Option :value="parseInt(4)">转账</Option>
                        </Select>
                    </FormItem>
                    <FormItem label="金额" prop='sampleInfoEntity.monney'>
                        <Input :disabled="status" v-model="sampleComplete.sampleInfoEntity.monney"  placeholder="请输入金额" number />
                    </FormItem>                    
                    <FormItem label="凭证号" v-show="sampleComplete.sampleInfoEntity.payment==3">  
                        <Input :disabled="status" v-model="sampleComplete.sampleInfoEntity.voucherno" placeholder="请输入凭证号" />
                    </FormItem>
                </div>
                <div class="title">备注</div>
                <div class="info suittextarea">
                    <Input :disabled="status" v-model="sampleComplete.sampleInfoEntity.remark" type="textarea"   placeholder="特殊情况说明(开票信息等)" />
                </div>
                <div class="title">上传附件
                    <span class="title-right" v-show="imgInfo.length>0">
                      <Button @click="trashVisible=true" v-if="!trashVisible">删除</Button>
                      <Button @click="trashVisible=false" v-else>取消</Button>
                    </span>
                </div>
                <div class="info ">                          
                    <div class="demo-upload-list" v-for="(item,index) in imgInfo" :key="index">
                        <img :src="item.src" @click="handleView(index)">                                 
                        <div class="demo-upload-list-cover" v-show="trashVisible">
                            <Icon type="ios-trash-outline" @click.native="handleRemove(index)"></Icon>
                        </div>
        
                        <Modal v-model="item.visible" >
                          <p slot="header">预览</p>
                          <img :src="item.src" style="width: 100%">
                          <div slot="footer"></div>
                        </Modal>   
                    </div>
                    <Upload
                        ref="upload"
                        :show-upload-list="false"
                        :on-success="uploadSuccess" :on-error="uploadError" 
                        :format="['jpg','jpeg','png']"
                        multiple
                        type="drag"
                        :action="uploadUrl"
                          class="demo-upload-wrap">
                        <div class="demo-upload-camera" >
                            <Icon type="ios-camera" ></Icon>
                        </div>
                    </Upload>                     
                  </div>
              </Form>
          </div>   
        </div>
        
    </div>
</template>

<script>
import topBar from "@/views/component/topbar.vue";
import { sampleData } from "api/index.js";
// import {Loading} from 'vux'
export default {
  name: "geneticTumor",
  data() {
    const validateMonney = (rule, value, callback) => {
      if (!value || value === "") {
        callback(new Error("金额不能为空"));
      } else if (!Number.isInteger(value)) {
        callback(new Error("金额只能输入数字"));
      } else {
        //  else if(this.sampleComplete.sampleInfoEntity.paymentMethod=="预付" && this.payment<value){
        //   callback(new Error("金额不能大于预付款金额"))
        // }
        callback();
      }
    };
    const validateDate = (rule, value, callback) => {
      if (!value || value === "") {
        callback(new Error("日期不能为空"));
      } else {
        callback();
      }
    };
    const validateAge = (rule, value, callback) => {
      if (!value || value === "") {
        callback(new Error("年龄不能为空"));
      } else if (!Number.isInteger(value)) {
        callback(new Error("年龄只能输入数字"));
      } else {
        callback();
      }
    };
    const validateOrder = (rule, value, callback) => {
      if (!value || value === "") {
        callback(new Error("快递单号不能为空"));
      } else if (value.length<10 ||value.length>14) {
        callback(new Error("快递单号格式不正确"));
      } else {
        callback();
      }
    };
    return {
      spinShow: false,
      imgInfo: [],
      trashVisible: false,
      uploadList: [],
      formTitle: "遗传性肿瘤",
      partShow: true,
      status: true,
      personToggle: true,
      familyToggle: true,
      projectToggle: true,
      moneyStatus: true,
      uploadUrl: "",
      agentList: [],
      hospitalList: [],
      payment: 0, //预付款余额
      addressList: [],
      sampleComplete: {
        sampleInfoEntity: {
          birthday: "", //要使日期选中值能显示要在这里先定义初始化，不知道为嘛
          sampleDate: Mcake.getFormateDate(new Date()), //this.formatDate(new Date()),
          allImg: [],
          sampleModeArray: []
        },
        familySampleEntityList: [],
        sampleValidateInfoEntityList: []
      },
      validatevBirthday: validateDate,
      validateAge: validateAge,
      ruleFormOne: {
        "sampleInfoEntity.name": {
          required: true,
          message: "姓名不能为空",
          trigger: "blur"
        },
        "sampleInfoEntity.sex": {
          required: true,
          message: "性别不能为空",
          trigger: "change"
        },
        "sampleInfoEntity.birthday": {
          required: true,
          validator: validateDate,
          trigger: "change"
        },
        "sampleInfoEntity.sampleNum": {
          required: true,
          message: "样本编号不能为空",
          trigger: "blur"
        },
        "sampleInfoEntity.cancerType": {
          required: true,
          message: "癌症类型不能为空",
          trigger: "blur"
        },
        "sampleInfoEntity.age": {
          required: true,
          validator: validateAge,
          trigger: "blur"
        },
        "sampleInfoEntity.testType": {
          required: true,
          message: "检测类型不能为空",
          trigger: "change"
        },
        "sampleInfoEntity.sampleDate": {
          required: true,
          validator: validateDate,
          trigger: "change"
        },
        "sampleInfoEntity.sampleModeArray": {
          required: true,
          type: "array",
          message: "样本类型不能为空",
          trigger: "change"
        },
        "sampleInfoEntity.addressMessage": {
          required: true,
          message: "报告邮寄信息不能为空",
          trigger: "blur"
        }
      },
      ruleFormTwo: {
        "sampleInfoEntity.logOrderNum": {
          required: true,
          // message: "快递单号不能为空",
          validator:validateOrder,
          trigger: "blur"
        },
        "sampleInfoEntity.monney": {
          required: true,
          validator: validateMonney,
          trigger: "blur"
        },
        "sampleInfoEntity.paymentMethod": {
          required: true,
          message: "支付方式不能为空",
          trigger: "change"
        }
      }
    };
  },
  methods: {
    partToggle(param) {
      this.partShow = param.btnToggle;
    },
    toggleEditStatus() {
      this.status = false;
      if (this.$store.state.btnTemp) {
        this.moneyStatus = false;
      } else {
        this.moneyStatus = true;
      }
    },
    clickNextStep(param) {
      window.scrollTo(0, 0);
      this.$refs["sampleCompleteOne"].validate(valid => {
        if (valid) {
          this.$refs.topbar.showPartTwo();
        } else {
          this.$Message.error("请把信息填完整");
        }
      });
    },
    saveItem(param) {
      let firstSaveStatus = false;
      this.$refs["sampleCompleteOne"].validate(valid => {
        if (valid) {
          this.$refs.topbar.showPartTwo();
          firstSaveStatus = true;
        } else {
          this.$Message.error("请把信息填完整");
        }
      });
      if (firstSaveStatus) {
        let obj = this.standardDate(1); //status 0暂存 1保存
        this.$refs["sampleCompleteTwo"].validate(valid => {
          if (valid) {
            //验证通过
            this.tempAndSave(obj);
          } else {
            this.$Message.error("请把信息填完整");
          }
        });
      }
    },
    saveTemp() {
      let obj = this.standardDate(0); //status 0暂存 1保存
      this.tempAndSave(obj);
    },
    standardDate(status) {
      let obj = this.sampleComplete;

      if (obj.sampleInfoEntity) {
        obj.sampleInfoEntity.status = status;
        if (obj.sampleInfoEntity.birthday == "") {
          obj.sampleInfoEntity.birthday = null;
        } else {
          obj.sampleInfoEntity.birthday = Mcake.getFormateDate(
            obj.sampleInfoEntity.birthday
          );
        }
        if (obj.sampleInfoEntity.sampleDate == "") {
          obj.sampleInfoEntity.sampleDate = null;
        } else {
          obj.sampleInfoEntity.sampleDate = Mcake.getFormateDate(
            obj.sampleInfoEntity.sampleDate
          );
        }
      }
      obj.sampleValidateInfoEntityList.forEach(element => {
        if (element.vBirthday == "") {
          element.vBirthday = null;
        } else {
          element.vBirthday = Mcake.getFormateDate(element.vBirthday);
        }
      });
      return obj;
    },
    tempAndSave(obj) {
      let status = obj.sampleInfoEntity.status;
      if (this.$store.state.operation == "add") {
        this.spinShow = true;
        sampleData
          .saveGeneticTumorPerson(obj)
          .then(res => {
            if (res.code == 0) {
              if (status == 0) {
                this.$Message.success("暂存成功");
                this.$router.push("/index");
              } else {
                this.$Message.success("保存成功");
                this.$router.push("/mySample");
              }
            } else if (res.code == 500) {
              this.spinShow = false;
              this.$Message.error(res.msg);
            } else {
              this.$Message.error(res.msg);
            }
          })
          .catch(error => {
            this.$Message.error(error);
          });
      } else {
        this.spinShow = true;
        if (this.$store.state.btnTemp && status == 1) {
          //从暂存到保存，调新增接口扣金额
          sampleData
            .saveGeneticTumorPerson(obj)
            .then(res => {
              if (res.code == 0) {
                this.$Message.success("保存成功");
                this.$router.push("/mySample");
              } else if (res.code == 500) {
                this.spinShow = false;
                this.$Message.error(res.msg);
              } else {
                this.$Message.error(res.msg);
              }
            })
            .catch(error => {
              this.$Message.error(error);
            });
        } else {
          sampleData
            .updateGeneticTumorPerson(obj)
            .then(res => {
              if (res.code == 0) {
                if (status == 0) {
                  this.$Message.success("暂存修改成功");
                  this.$router.push("/index");
                } else {
                  this.$Message.success("修改成功");
                  this.$router.push("/mySample");
                }
              } else if (res.code == 500) {
                this.spinShow = false;
                this.$Message.error(res.msg);
              } else {
                this.$Message.error(res.msg);
              }
            })
            .catch(error => {
              this.$Message.error(error);
            });
        }
      }
    },
    getGeneticTumorInfo() {
      let obj = {
        id: this.$store.state.sampleid
      };
      sampleData
        .getGeneticTumorPerson(obj)
        .then(res => {
          if (res.code == 0 || res.code == 200) {
            this.sampleComplete = res.sampleComplete;
            let showAgentId = this.sampleComplete.sampleInfoEntity.agentid;
            if (showAgentId) {
              this.getHospitalListByAgentId(showAgentId);
              this.getAgentById(showAgentId);
            }
            let allImg = this.sampleComplete.sampleInfoEntity.allImg;
            if (allImg) {
              //图片不为空才能使用forEach
              allImg.forEach(element => {
                //显示图片
                this.imgInfo.push({ src: element, visible: false });
              });
            }
          } else {
            this.$Message.error(res.msg);
          }
        })
        .catch(error => {
          this.$Message.error(error);
        });
    },
    addPositive() {
      this.sampleComplete.sampleValidateInfoEntityList.push({
        vname: "",
        vBirthday: "",
        sex: "",
        kinship: "",
        sampleNum: "",
        isHaveb: "",
        bName: ""
      });
    },
    deletePositive(index) {
      this.sampleComplete.sampleValidateInfoEntityList.splice(index, 1);
    },
    deleteRelativeHistory(index) {
      this.sampleComplete.familySampleEntityList.splice(index, 1);
    },
    addRelativeHistory() {
      this.sampleComplete.familySampleEntityList.push({
        fname: "",
        fkinship: "",
        fcancerType: "",
        isManyLesion: ""
      });
    },
    uploadSuccess(response, file, fileList) {
      if (response.code == 0 || response.code == 200) {
        if (!this.sampleComplete.sampleInfoEntity.allImg) {
          //为null需初始化
          this.sampleComplete.sampleInfoEntity.allImg = new Array();
        }
        this.sampleComplete.sampleInfoEntity.allImg.push(response.msg);

        this.imgInfo.push({ src: response.msg, visible: false });
      } else {
        this.$Message.error(response.msg);
        this.$refs.upload.clearFiles();
      }
    },
    uploadError(error, file, fileList) {
      this.$Message.error(error.msg);
    },
    handleRemove(index) {
      this.sampleComplete.sampleInfoEntity.allImg.splice(index, 1);
      this.imgInfo.splice(index, 1);
    },
    handleView(index) {
      this.imgInfo[index].visible = true;
    },
    confirmDate(type, index) {
      console.log(type, index);
      let dtPicker = new mui.DtPicker({
        type: "date",
        beginYear: 1860,
        endDate: new Date()
      });
      dtPicker.show(selectItems => {
        if (type == "birthday") {
          this.sampleComplete.sampleInfoEntity.birthday = selectItems.text;
          this.$refs.sampleCompleteOne.validateField(
            "sampleInfoEntity.birthday"
          );
        }
        if (type == "sampleDate") {
          this.sampleComplete.sampleInfoEntity.sampleDate = selectItems.text;
          this.$refs.sampleCompleteOne.validateField(
            "sampleInfoEntity.sampleDate"
          );
        }
        if (type == "VBirthday") {
          this.sampleComplete.sampleValidateInfoEntityList[index].vBirthday =
            selectItems.text;
          this.$refs.sampleCompleteOne.validateField(
            "sampleValidateInfoEntityList." + index + ".vBirthday"
          );
        }
      });
    },
    getAgentListByUserId() {
      let obj = {};
      sampleData
        .getAgentListByUserId(obj)
        .then(res => {
          if (res.code == 0 || res.code == 200) {
            this.agentList = res.list;
          } else {
            this.$Message.error(res.msg);
          }
        })
        .catch(error => {
          this.$Message.error(error);
        });
    },
    getHospitalListByAgentId(agentId) {
      let obj = {
        agentId: agentId
      };
      sampleData
        .getHospitalListByAgentId(obj)
        .then(res => {
          if (res.code == 0 || res.code == 200) {
            this.hospitalList = res.list;
          } else {
            this.$Message.error(res.msg);
          }
        })
        .catch(error => {
          this.$Message.error(error);
        });
    },
    getAgentById(agentId) {
      let obj = {
        id: agentId
      };
      sampleData
        .getAgentById(obj)
        .then(res => {
          if (res.code == 0 || res.code == 200) {
            this.payment = res.agentEntity.payment || 0;
          } else {
            this.$Message.error(res.msg);
          }
        })
        .catch(error => {
          this.$Message.error(error);
        });
    },
    agentChange(agentId) {
      this.sampleComplete.sampleInfoEntity.hospitalid = "";
      this.getHospitalListByAgentId(agentId);
      this.getAgentById(agentId);
    },
    getAddressMessage(){
      let obj={};
      sampleData.addressMessage(obj).then(res=>{
        if(res.code==0||res.code==200){
          let setList=new Set(res.list); //消除数组中的重复
          this.addressList=[...setList];  //set数据结构转为数组
        }else{
          this.$Message.error(res.msg)
        }
      }).catch(error=>{
        this.$Message.error(error)
      })
    },
    filterAddress(value,option) {
      return option.indexOf(value)!==-1         
    }
  },
  mounted() {
    if (this.$store.state.operation == "edit") {
      this.getGeneticTumorInfo();
      this.status = true;
      this.moneyStatus = true;
    } else {
      this.status = false;
      this.moneyStatus = false;
    }

    this.uploadUrl = this.$store.state.uploadUrl;
    this.getAgentListByUserId();
    this.getAddressMessage();
  },
  components: {
    topBar
    // Loading
  }
};
</script>


